package com.zss.staff.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zss.pojo.Employee;
import com.zss.pojo.TbArea;
import com.zss.pojo.vo.TbAreaVo;
import com.zss.staff.service.AreaService;
import com.zss.staff.service.EmployeeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("staff/area")
public class AreaController {

    @Resource
    AreaService areaService;
    @Resource
    EmployeeService employeeService;

    @RequestMapping("list")
    public List<TbArea> list(){
        return areaService.list();
    }

    @RequestMapping("getByUid")
    public TbArea getByUid(HttpServletRequest request){
        String openId = (String) request.getSession().getAttribute("openId");
        LambdaQueryWrapper<Employee> queryWapper = new LambdaQueryWrapper<Employee>();
        queryWapper.eq(Employee::getOpenid,openId);
        Employee employee = employeeService.getOne(queryWapper);
        return areaService.getById(employee.getAid());
    }

    @RequestMapping("selectListAll")
    @ResponseBody
    public List<TbAreaVo> selectListAll(){
        return areaService.selectListAll();
    }

}
